import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
//AntDesign Load
import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers';
//Legacy Browser
import legacy from '@vitejs/plugin-legacy';
//@ alias = src
import {join} from 'path'

function resolve(dir: string) {
  return join(__dirname, dir);
}

export default defineConfig(({mode}) => {
  const envConfig = loadEnv(mode, './')
  return {
    plugins: [
      vue(),
      //AntDesign Load
      Components({
        resolvers: [AntDesignVueResolver()],
      }),
      //Legacy Browser
      legacy({
        targets: ['defaults', 'not IE 11'],
        renderLegacyChunks: false
      })
    ],
    //env process
    envDir: './',
    build: {
      manifest: true,
      outDir: `./dist/${mode}`
    },
    resolve: {
      alias: {
        '@': resolve('src'),
      }
    },
    //build remove console
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  }
})